﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for CityBusiness
/// </summary>
public class CityBusiness
{
	public CityBusiness()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public bool Insert(CityEntities item)
    {
        bool flat = false;
        string[] para = { "@citySymbol", "@cityName", "@countryID", "@cityInfo" };
        string[] values = { item._citySymbol,item._cityName,item._countryID.ToString(),item._cityInfo };
        if (DataAccess.getExecProcedure("sp_InsertCity", para, values) > 0)
        {
            flat = true;
        }
        else
            flat = false;
        return flat;
    }

    public bool Edit(CityEntities item)
    {
        bool flat = false;
        string[] para = { "@cityID","@citySymbol", "@cityName", "@countryID", "@cityInfo" };
        string[] values = { item._cityID.ToString(),item._citySymbol, item._cityName, item._countryID.ToString(), item._cityInfo };
        if (DataAccess.getExecProcedure("sp_UpdateCity", para, values) > 0)
            flat = true;
        else
            flat = false;
        return flat;
    }

    public bool Delete(int id)
    {
        if (DataAccess.getExec("exec sp_DeleteCity'"+id+"'") > 0)
            return true;
        else
            return false;
    }

    public DataTable getIntroduction(string citySymbol)
    {
        return DataAccess.DataTable_Query("exec sp_Introduction '" + citySymbol + "'");
    }

    public DataTable getAllCity()
    {
        return DataAccess.DataTable_Query("exec sp_GetAllCity '0'");
    }

    public CityEntities getCity(int id){
        CityEntities ce = new CityEntities();
        DataTable dt = DataAccess.DataTable_Query("exec sp_GetAllCity '"+id+"'");
        if (dt != null)
        {
            DataRow dr = dt.Rows[0];
            ce._cityID = int.Parse(dr["cityID"].ToString());
            ce._citySymbol = dr["citySymbol"].ToString();
            ce._cityName = dr["cityName"].ToString();
            ce._countryID = int.Parse(dr["countryID"].ToString());
            ce._cityInfo = dr["cityInfo"].ToString();
        }
        return ce;
    }

    public DataTable getCityBy(string[] TableName, string[] fields, string Criterias, string priorities)
    {
        DataTable dt = new DataTable();
        string query = SQLQuery.SQLQuery_SELECT(TableName, fields, Criterias, priorities);
        return dt = DataAccess.DataTable_Query(query);
    }
}